package com.luyu.controller;

import com.luyu.req.UserLoginReq;
import com.luyu.res.ResultRes;
import com.luyu.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping({"/auth"})
public class AuthController {

    @Resource
    private UserService userService;



    @GetMapping({"/login/detail"})
    public UserDetails sendConfirm(@RequestParam Long id) {
        return this.userService.detail(id);
    }


    @PostMapping({"/login/access/token"})
    public ResultRes<String>login(@RequestBody UserLoginReq req) {
       return ResultRes.success(userService.loginToken(req));
    }

    @PostMapping({"/{tenantId}/user/current/role"})
    public ResultRes<Boolean> replaceCurrentRole(@PathVariable("tenantId") Long tenantId,@RequestParam Long roleId) {
        return ResultRes.success(userService.replaceCurrentRole(roleId));
    }

    @GetMapping({"/{tenantId}/user/kick/out"})
    public ResultRes<Boolean> kickOutUser(@PathVariable("tenantId") Long tenantId,@RequestParam String userName) {
        return ResultRes.success(userService.kickOut(userName));
    }

}
